﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace masini
{
    class CoupePool : CarsFactory
    {
        static CoupePool _instance;
        List<CoupeCar> cars;

        private CoupePool()
        {
            cars = new List<CoupeCar>();
            cars.Add(new CoupeCar("bmw", "rosu", "automata", "piele", "diesel", "2m"));
            cars.Add(new CoupeCar("mercedes", "rosu", "automata", "navigatie", "otto", "2.2m"));
            cars.Add(new CoupeCar("audi", "rosu", "automata", "clima", "diesel", "2.1m"));
        }

        public static CoupePool Instance()
        {
            if (_instance == null)
                _instance = new CoupePool();

            return _instance;
        }

        public override void Put(Car s)
        {
            if (s.GetType().ToString().Split('.')[1] == "CoupeCar")
                cars.Add((CoupeCar)s);
            else
                Console.WriteLine("Tipul masini nu corespunde cu pool-ul");
        }

        public override Car SearchByName(string name, bool sterge)
        {
            Car aux = new CoupeCar();
            bool ok = false;
            foreach (Car c in cars)
            {
                if (c.getName() == name)
                {
                    aux = c;
                    ok = true;
                }
            }
            if (ok == true)
            {
                if (sterge)
                    cars.Remove((CoupeCar)aux);
                return aux;
            }
            return new CoupeCar();
        }
    
    }
}
